<div class="content">
    <!--- Bread Crumbs Menu -->
    <div class="breadLine">
        <ul class="breadcrumb">
            <li><a href="/">Admin</a> <span class="divider">></span></li>
            <li class="active"><a href="/">User</a> <span class="divider">></span></li>     
            <li class="active"><?php echo Config::get_page(); ?></li>
        </ul>
        <?php
            //echo $this->setLayout("breadcrumbs_right_menu");
        ?>
    </div>

   <div class="workplace">
        
    
        <div class="row-fluid">
            <div class="span12">
                <div class="head clearfix">
                    <div class="isw-calendar"></div>
                        <div class="span5">
                            <h1><?php echo Config::get_page(); ?></h1>
                        </div>
                        <div class="span3 pull-right"></div>
                    </div>
                    
                    <div class="row-fluid">
                        <div class="span12">
                            <div class="widget">
                                <div class="head dark">
                                    <div class="icon title_icon"><i class="fa fa-users"></i></div>
                                    <h2>Role And Access Set Up</h2>
                                </div>  
                                <div class="block-fluid">
                                    <form id="access_role" class="formular" method="POST" action="/ajax/role-configuration?action=role_access&type=set">
                                        <div class="row-form">
                                            <div class="span12">
                                                <div class="span6">
                                                    <div class="span3">Search:</div>
                                                    <div class="span9"><input type="text" placeholder="Placeholder example" style="margin-left: -5px;"/></div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="row-form">
                                            <div class="span12">
                                                <div class="span3">
                                                    <div class="span6">Page Access:</div>
                                                    <div class="span6">
                                                        <?php
                                                            $db = new Database();
                                                            $rf = new Role_Functions();
                                                            echo Library::page_access("page_access","","validate[required]","",""," ");
                                                        ?>
                                                    </div>
                                                </div>
                                                <div class="span3">
                                                    <div class="span6">Role:</div>
                                                    <div class="span6">
                                                        <select name="role_access" class="validate[required]">
                                                            <?php
                                                                echo $rf->load_roles($db," ");
                                                            ?>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="span6">
                                                    <div class="span6">Access:</div>
                                                    <div class="span6">
                                                        <input type="checkbox" name="access_type[]" checked="checked" value="None"/>None 
                                                        <input type="checkbox" name="access_type[]" value="Read"/>Read 
                                                        <input type="checkbox" name="access_type[]" value="Write"/>Write 
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="span12" style="margin-left:0;margin-top: -15px;margin-bottom: -15px;">
                                                <div class="pull-right">
                                                    <input type="submit" class="btn btn-primary" value="Add">
                                                    <!--<button class="btn btn-primary" type="button" id="access_add">Add</button>-->
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                                <div class="row-fluid">
                                    <div class="block-fluid">
                                        <table class="tb_brochure" cellpadding="0" cellspacing="0" width="100%">
                                            <thead>
                                                <tr>
                                                    <th>
                                                       Page Access
                                                    </th>
                                                    <th>
                                                       Role
                                                    </th>
                                                    <th>
                                                       Access
                                                    </th>
                                                    <th>
                                                       Action
                                                    </th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php
                                                    $db = new Database();
                                                    $fs = new Functions();
                                                    $ra_query = $db->query("SELECT * FROM " . $db->tbl_name(TB_ROLE_ACCESS) . " WHERE is_active={$db->escape(1)}","array");
                                                    foreach($ra_query as $data){
                                                        $Roles = new Roles($db,$data['level_id']);
                                                        $encrypted_id = $fs->base_encode_decode("encrypt", $data['id']);
                                                        $remove_sp_char = str_replace("[", "", $data['access_type']);
                                                        $remove_sp_char = str_replace('\"', "", $remove_sp_char);
                                                        $remove_sp_char = str_replace('\"', "", $remove_sp_char);
                                                        $remove_sp_char = str_replace("]", "", $remove_sp_char);
                                                        $arr = array("page_access"     =>  $data['page_access'],
                                                                    "role_id"          =>  $data['level_id'],
                                                                    "access_type"      =>  $remove_sp_char);
                                                        
                                                        
                                                        echo '<tr id="tr_' . $encrypted_id . '" data-json="' . htmlentities(json_encode($arr)) . '">';
                                                            echo '<td>' . $data['page_access'] . '</td>';
                                                            echo '<td>' . $Roles->role_name . '</td>';
                                                            
                                                            echo '<td>' . $remove_sp_char . '</td>';
                                                            echo '<td class="TAC" data-id="' .$encrypted_id . '">';
                                                                echo '<a class="trigger_settings tip cursor" data-type="edit" data-original-title="Edit this role access."><span class="icon-pencil"></span></a>'; 
                                                                echo '<a class="trigger_settings tip cursor" data-type="remove" data-original-title="Remove this role access"><span class="icon-trash"></span></a>'; 
                                                            echo '</td>';
                                                        echo '</tr>';
                                                        //echo ;
                                                    }
                                                ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>  
                    </div>
                    
                </div>
            </div>    
        </div>
   </div>

</div>